#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>


#define filename "log.txt"

int main()
{
    fprintf(stdout, "normal message\n");
    fprintf(stdout, "normal message\n");
    fprintf(stdout, "normal message\n");
    fprintf(stdout, "normal message\n");
    fprintf(stdout, "normal message\n");

    fprintf(stderr, "error message\n");
    fprintf(stderr, "error message\n");
    fprintf(stderr, "error message\n");
    fprintf(stderr, "error message\n");
    fprintf(stderr, "error message\n");

    //int fd=open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0666);
    //if(fd < 0)
    //{
    //    perror("open");
    //    return 1;
    //}

    //dup2(fd, 1);
    //printf("fd: %d\n", fd);
    //printf("hello printf\n");
    //fprintf(stdout, "hello fprintf\n");

    //char buffer[128];
    //ssize_t s=read(0, buffer, strlen(buffer)-1);
    //if(s>0)
    //{
    //    buffer[s]='\0';
    //    printf("echo: %s\n", buffer);
    //}

    //close(1);
    //umask(2);
    //int fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0666);
    //if(fd < 0)
    //{
    //    perror("open");
    //    return 1;
    //}

    //// 重定向
    //dup2(fd, 1);

    ////printf("fd: %d\n", fd);
    //int count=5;
    //const char* msg="Hello Linux\n";
    //while(count)
    //{
    //    write(1, msg, strlen(msg));
    //    count--;
    //}

    //close(fd);

    return 0;
}
